/*
 * Copyright 2014 by Kuaipao Corporation
 * 
 * All Rights Reserved
 * 
 * File name  : arp_inspection.h
 * Function   : ARP Inspection Include File (ps: DHCP Snooping, DHCP Relay)
 * Auther     : eagles.zhou 
 * Version    : 1.0
 * Date       : 2014/01/18
 *
 *********************Revision History****************
 Date       Version    Modifier   Modifications
 2014/1/1   1.01       eagles     ARP Inspection function
 
 */

#ifndef ARPPROXY_H
#define ARPPROXY_H

typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long uint64;
//#include "nvram.h"
//#include "if_info.h"
//#include "bcmutils.h"

#define PACKED __attribute__((packed))

#define ARPPROXY_USE_DYNAMIC

/*
 * Define return value
 */
#define ARP_SUCCESS 0
#define ARP_FAILED  1

#define SERVER_PORT		67
#define CLIENT_PORT		68

#define IP_ADDR_LEN  4
#define MAC_ADDR_LEN 6
#define ETH_ALEN 6

#define MAX_MSG_SIZE 1528
#define DEFAULT_LEASE_TIME 86400
#define DEFAULT_TIMEOUT 60

#define RELAY_TIMEOUT 20

#define ETH_HW_ADDR_LEN         6 
#define IP_ADDR_LEN             4 
#define ARP_FRAME_TYPE          0x0806 
#define ETHER_HW_TYPE           1 
#define IP_PROTO_TYPE           0x0800 

/* Arp packet field offset */ 
#define ARP_HW_TYPE_OFF         14 
#define ARP_PROT_TYPE_OFF       16 
#define ARP_HW_ADDR_LEN_OFF     18 
#define ARP_PROT_ADDR_LEN_OFF   19 
#define ARP_OPCODE_OFF          20 
#define ARP_SRC_MAC_OFF         22 
#define ARP_SRC_IP_OFF          28 
#define ARP_DST_MAC_OFF         32 
#define ARP_DST_IP_OFF          38
#define ETH_NAME 32

#define ARP_CONFIG_FILE "/tmp/arp_config"

typedef struct binding_info_t {
	int hash_index;
	int timeout;
	uint64 ip_vlan;
	uint64 port_vlan;
}binding_info;

typedef struct {
	uint8 ether_dhost[MAC_ADDR_LEN];
	uint8 ether_shost[MAC_ADDR_LEN];
	uint16 ether_type;
} PACKED ETHHDR;

typedef struct {
    uint16  ar_hrd;         /* format of hardware address   */
    uint16  ar_pro;         /* format of protocol address   */
    uint8   ar_hln;         /* length of hardware address   */
    uint8   ar_pln;         /* length of protocol address   */
    uint16  ar_op;          /* ARP opcode (command)         */
}PACKED ARPHDR;

typedef struct {
    uint8   ar_sha[6];       /* sender hardware address      */
    uint8   ar_sip[4];              /* sender IP address            */
    uint8   ar_tha[6];       /* target hardware address      */
    uint8   ar_tip[4];              /* target IP address            */
}PACKED ARPMSG;

typedef struct {
	ETHHDR ethhdr;
	ARPHDR arphdr;
	ARPMSG arpmsg;
} PACKED ARPPkts;

typedef struct 
{
    uint8   targ_hw_addr[ETH_HW_ADDR_LEN];
    uint8   src_hw_addr[ETH_HW_ADDR_LEN];
    uint16  vlan_type;
    uint16  vlan_id;
    uint16  frame_type;
    uint16  hw_type;
    uint16  prot_type;
    uint8   hw_addr_size;
    uint8   prot_addr_size;
    uint16  op;
    uint8   sndr_hw_addr[ETH_HW_ADDR_LEN];
    uint32  sndr_ip_addr;
    uint8   rcpt_hw_addr[ETH_HW_ADDR_LEN];
    uint32  rcpt_ip_addr;
    uint8   padding[18];
}PACKED VARP_PACKET;


typedef struct 
{
    uint8   targ_hw_addr[ETH_HW_ADDR_LEN];
    uint8   src_hw_addr[ETH_HW_ADDR_LEN];
    uint16  frame_type;
    uint16  hw_type;
    uint16  prot_type;
    uint8   hw_addr_size;
    uint8   prot_addr_size;
    uint16  op;
    uint8   sndr_hw_addr[ETH_HW_ADDR_LEN];
    uint32  sndr_ip_addr;
    uint8   rcpt_hw_addr[ETH_HW_ADDR_LEN];
    uint32  rcpt_ip_addr;
    uint8   padding[18];
}PACKED ARP_PACKET;


#endif	//ARPPROXY_H

